<template>
  <el-form ref="formRef" :model="form" label-width="280px" status-icon>
    <el-form-item label="自动收货时间(天)" prop="auto_receive_time">
      <el-input v-model="form.auto_receive_time" clearable style="width: 240px"/>
    </el-form-item>
    <el-form-item label="警戒库存数" prop="warning_store">
      <el-input v-model="form.warning_store" clearable style="width: 240px"/>
    </el-form-item>
    <el-form-item label="普通商品未支付取消订单时间(小时)" prop="com_unpaid_cancel_time">
      <el-input v-model="form.com_unpaid_cancel_time" clearable style="width: 240px"/>
    </el-form-item>
    <el-form-item label="活动商品未支付取消订单时间(小时)" prop="activity_unpaid_cancel_time">
      <el-input v-model="form.activity_unpaid_cancel_time" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item label="砍价未支付取消订单时间(小时)" prop="cut_unpaid_cancel_time">
      <el-input v-model="form.cut_unpaid_cancel_time" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item label="秒杀未支付订单取消时间(小时)" prop="seckill_unpaid_cancel_time">
      <el-input v-model="form.seckill_unpaid_cancel_time" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item label="拼团未支付取消订单时间(小时)" prop="collage_unpaid_cancel_time">
      <el-input v-model="form.collage_unpaid_cancel_time" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item label="自动好评时间(小时)" prop="auto_goods_appraise">
      <el-input v-model="form.auto_goods_appraise" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item label="余额充值未支付订单取消时间(小时)" prop="recharge_balance_cancel_time">
      <el-input v-model="form.recharge_balance_cancel_time" clearable  style="width: 240px"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" plain v-debounce="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getConfig } from "@/api/system/config";

// 定义参数的类型
interface IConfigProps {
  configKey?: string;
  name?: string;
}

// 子组件接收父组件的值
// withDefaults：设置默认值  defineProps：接收父组件的参数
const props = withDefaults(defineProps<IConfigProps>(), {
  name: "",
  configKey: ""
});

onMounted(() => {
  getConfig({ key: props.configKey }).then(res => {
    if (Object.keys(res.data).length > 0) {
      form.value = res.data;
    }
  });
});

// 当前组件获取父组件传递的事件方法
const emits = defineEmits(["handleSubmit"]);
// 弹框的确定事件
const handleSubmit = () => {
  emits("handleSubmit", form.value);
};

let form = ref<any>({
  auto_receive_time: "",
  warning_store: "",
  com_unpaid_cancel_time: "",
  activity_unpaid_cancel_time: "",
  cut_unpaid_cancel_time: "",
  seckill_unpaid_cancel_time: "",
  collage_unpaid_cancel_time: "",
  auto_goods_appraise: "",
  recharge_balance_cancel_time: ""
});
</script>

<style lang="scss" scoped></style>
